package cn.edu.scau.cmi.mazhuanglong.fxml;


import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.mazhuanglong.singleton.Chairman;
import cn.edu.scau.cmi.mazhuanglong.singleton.Marshal;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class SingletonController {

//    @FXML
//    private ResourceBundle resources;
//
//    @FXML
//    private URL location;

	@FXML 
	private Button button1;
	@FXML 
	private Button button2;
    @FXML
    private Label output1;

    @FXML
    private Label output2;

    @FXML
    private TextField input1;

    @FXML
    private TextField input2;
    
   @FXML
    void createChairman(ActionEvent event) {
    	String name = input1.getText();
    	Chairman chairman = Chairman.getInstance(name);
    	String message = output1.getText();
    	if(message != null)message =message+ "\n";
    	message += "名称： "+chairman.getName()+"\n对象： "+chairman;
    	//System.out.print(chairman+"\n");
    	output1.setText(message);
    }

    @FXML
    void createMarshal(ActionEvent event) {
    	String name = input2.getText();
    	Marshal marshal = Marshal.getInstance(name);
    	String message = output2.getText();
    	if(message != "") message += "\n";
    	if(marshal != null)
    		message += "名称： "+marshal.getName()+"\n对象： "+marshal;
    	else
    		message += "你已经创建了10个元帅了，不能再创建了！";
    	output2.setText(message);
    	
    }

//    @FXML
//    void initialize() {
//        assert output1 != null : "fx:id=\"output1\" was not injected: check your FXML file 'singleton.fxml'.";
//        assert output2 != null : "fx:id=\"output2\" was not injected: check your FXML file 'singleton.fxml'.";
//        assert input2 != null : "fx:id=\"input2\" was not injected: check your FXML file 'singleton.fxml'.";
//        assert input1 != null : "fx:id=\"intput1\" was not injected: check your FXML file 'singleton.fxml'.";
//
//    }
}
